import { HttpMethod } from '@/services/types';
import { request } from '@/api/request';

/**
 * GET /address 获取地址列表
 * @param options
 */
export async function resAddressList(
  options?: { [key: string]: any },
) {
  return request<API.AddressStruct[]>('/address', {
    method: HttpMethod.GET,
    ...(options || {}),
  });
}

/**
 * GET /address/:id 获取地址详情
 * @param id
 * @param options
 */
export async function resAddressDetail(
  id:number,
  options?: { [key: string]: any },
) {
  return request<R<API.AddressStruct[]>>('/address/'+id, {
    method: HttpMethod.GET,
    ...(options || {}),
  });
}

/**
 * GET /city 获取省市区数据
 * @param params
 * @param options
 */
export async function resCity(
  params: API.CityParams,
  options?: { [key: string]: any },
) {
  return request<API.CityStruct[]>('/city', {
    method: HttpMethod.GET,
    params,
    ...(options || {}),
  });
}

/**
 * Delete /address/:id 删除地址
 * @param id
 * @param options
 */
export async function resDeleteAddress(
  id:number,
  options?: { [key: string]: any },
) {
  return request<R<null>>('/address/'+id, {
    method: HttpMethod.DELETE,
    ...(options || {}),
  });
}

/**
 * POST /address 添加地址
 * @param params
 * @param options
 */
export async function resAddAddress(
  params: API.AddressParams,
  options?: { [key: string]: any },
) {
  return request<R<API.AddressStruct>>('/address', {
    method: HttpMethod.POST,
    data: params,
    ...(options || {}),
  });
}

/**
 * PATCH /address/default/:id 修改默认地址
 * @param id
 * @param options
 */
export async function resChangeAddressDefault(
  id: number,
  options?: { [key: string]: any },
) {
  return request<R<null>>('/address/default/' + id, {
    method: HttpMethod.PATCH,
    ...(options || {}),
  });
}

/**
 * PUT /address/:id 修改地址
 * @param id
 * @param params
 * @param options
 */
export async function resChangeAddress(
  id: number,
  params: API.AddressParams,
  options?: { [key: string]: any },
) {
  return request<R<null>>('/address/'+id, {
    method: HttpMethod.PUT,
    data:params,
    ...(options || {}),
  });
}
